package com.lagou.mr.group;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class CustomGroupingComparator extends WritableComparator {

    //注册自定义的GroupingComparator接受OrderBean对象
    public CustomGroupingComparator() {
        super(OrderBean.class,true);
    }

    //重写其中的compare方法，通过这个方法来让mr接受orderid相等则两个对象相等的规则，key相等
    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        //比较两个对象的orderid
        OrderBean order1 =(OrderBean)a;
        OrderBean order2 =(OrderBean)b;
        return order1.getOrderId().compareTo(order2.getOrderId());
    }
}
